﻿using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LiteBlog.Common.Entities
{
    public class Category : IEqualityComparer<Category>
    {
        [Required(ErrorMessage="Please enter url name")]
        [RegularExpression(@"^[\S]*$", ErrorMessage="The url name cannot contain white spaces")]
        public string CatID { get; set; }

        [Required(ErrorMessage="Please enter display name")]
        public string Name { get; set; }

        public int Order { get; set; }
        public int Count { get; set; }

        public Category() : this(string.Empty, string.Empty) {}

        public Category(string catId, string name)
        {
            CatID = catId;
            Name = name;
            Order = Count = 0;
        }

        public bool Equals(Category x, Category y)
        {
            return x.CatID.Equals(y.CatID);
        }

        public int GetHashCode(Category obj)
        {
            return obj.CatID.GetHashCode();
        }

        public static IEqualityComparer<Category> Comparer
        {
            get
            {
                return new Category();
            }
        }
    }
}